package com.example.studyPlatform.bean;

import cn.lyf.currey.Tuple;

import java.util.Objects;

import static cn.lyf.currey.Tuple.Tuple1;

public class IdentifiableBean<T> {
    T id;

    public IdentifiableBean(T id) {
        this.id = id;
    }

    public IdentifiableBean() {
    }

    public T getId() {
        return id;
    }

    public void setId(T id) {
        this.id = id;
    }

    // 直接换一套操作
    Tuple1<T> tupled() {
        return Tuple.of(id);
    }

    public static <T> IdentifiableBean<T> of(Tuple1<T> tuple1) {
        return new IdentifiableBean<>(tuple1._1);
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof IdentifiableBean)) return false;
        IdentifiableBean<?> that = (IdentifiableBean<?>) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
